<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js canvas - combo camera - orthographic + perspective</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
				color: purple;
			}

			a {
				color: red;
			}


			canvas{
				position: fixed;
				width:300px;
				height:300px;
				z-index: 50000000;

				left:0px;
				top:50px;
			}

		</style>
	</head>
	<body>

		<script src="/static/three/build/three.js"></script>
<script src="/static/three/js/controls/OrbitControls.js"></script>
		<script src="/static/three/js/cameras/CombinedCamera.js"></script>

		<script src="/static/three/js/renderers/Projector.js"></script>
		<script src="/static/three/js/renderers/CanvasRenderer.js"></script>

		<script src="/static/three/js/libs/stats.min.js"></script>
		<script src = "/static/three/js/loaders/ColladaLoader.js"></script>


				
			<div id="fov"></div>
		</div>



		<script>

			var container, stats,controls;
			var camera, scene, renderer;
			var lookAtScene = true;

			init();
			animate();

			function setOrthographic() {

				camera.toOrthographic();

			

			}

			function setPerspective() {

				camera.toPerspective();

				document.getElementById('fov').innerHTML = 'Perspective mode' ;

			}
			 function initModel() {

					//辅助工具

				}

			function init() {
				
				container = document.createElement( 'div' );
				document.body.appendChild( container );

				//camera = new THREE.CombinedCamera( window.innerWidth / 2, window.innerHeight / 2, 70, 1, 1000, -500, 1000 );
					//CombinedCamera(width,height,fov(相机角度),near（相机的近平面视角）,far（远平面视角）,orthoNera（近平面视图）,orthoFar)
				camera = new THREE.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 1000 );
				

				
				//camera = new THREE.PerspectiveCamera(50,window.innerWidth/window.innerHeight,1,1000,1)
				//camera.lookAt(500,0,500);
				camera.position.x = 0;
				camera.position.y = 1000;
				camera.position.z =0;
				scene = new THREE.Scene();
				
				scene.add( camera );
				
				// Grid网格; 方格

				var size = 500, step = 10;

				var geometry = new THREE.Geometry();

				for ( var i = -size; i <= size; i += step ) {

					geometry.vertices.push( new THREE.Vector3( - size, 0, i ) );
					geometry.vertices.push( new THREE.Vector3(   size, 0, i ) );

					geometry.vertices.push( new THREE.Vector3( i, 0, - size ) );
					geometry.vertices.push( new THREE.Vector3( i, 0,   size ) );

				}






				var material = new THREE.LineBasicMaterial( { color:0x00000, opacity: 0.2 } );

				var line = new THREE.LineSegments( geometry, material );
				scene.add( line );

				// Cubes





				// Lights

				var ambientLight = new THREE.AmbientLight( 100 );
				scene.add( ambientLight );

				var directionalLight = new THREE.DirectionalLight(  0xffffff );
				directionalLight.position.x =600 - 0.5;
				directionalLight.position.y =1000 - 0.5;
				directionalLight.position.z = 1000 - 0.5;
				directionalLight.position.normalize();
				scene.add( directionalLight );

				var directionalLight = new THREE.DirectionalLight( 0xffffff );
				directionalLight.position.x = 4000 - 0.5;
				directionalLight.position.y = 5000 - 0.5;
				directionalLight.position.z = 8000 - 0.5;
				directionalLight.position.normalize();
				scene.add( directionalLight );

				renderer = new THREE.CanvasRenderer();
				renderer.setClearColor( 0xf0f0f0 );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize(255, 153 );
				container.appendChild( renderer.domElement );

				stats = new Stats();
				container.appendChild( stats.dom );

			/*	window.addEventListener( 'resize', onWindowResize, false );

				function onWindowResize(){

					camera.setSize( window.innerWidth, window.innerHeight );
					camera.updateProjectionMatrix();

					renderer.setSize( window.innerWidth, window.innerHeight );

				}*/

					const loader = new ColladaLoader( loadingManager );
				loader.load( './models/collada/test.dae', function ( collada ) {

					elf = collada.scene;
					 elf.scale.set(2,2,2);
       				 elf.position.set(100,5,5);

				} );


				
				var controls = new THREE.OrbitControls(camera);
				controls.maxPolarAngle=0;
				controls.minPolarAngle=0;
				controls.enableDamping = true;  
				//是否可以缩放  
				controls.enableZoom = true;  
				//是否自动旋转  
				controls.autoRotate = true;  
				//设置相机距离原点的最远距离  
				controls.minDistance = 1200;
				//设置相机距离原点的最远距离  
				controls.maxDistance = 1200;
				//是否开启右键拖拽  
				controls.enablePan = true; 
				
				controls.dampingFactor = 0.7;
				
				
				
		
				
				//坐标系
				//scene.add(axes);

			}

			//

			function animate() {

				requestAnimationFrame( animate );

				stats.begin();
				render();
				stats.end();

			}

			function render() {

				var timer = Date.now() * 0.0001;
				//旋转代码
				//camera.position.x = Math.cos( timer ) * 200;
				//camera.position.z = Math.sin( timer ) * 200;
				//if ( lookAtScene ) camera.lookAt( scene.position );
			
				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>
